package com.whz.gateway.common.util;

import lombok.experimental.UtilityClass;
import org.springframework.http.server.reactive.ServerHttpRequest;
import com.whz.gateway.limit.GatewayRemoteIpResolver;

import java.net.InetSocketAddress;

/**
 * @author whz
 */
@UtilityClass
public class GatewayIpUtils {

    public static String getRemoteIp(final ServerHttpRequest request) {
        InetSocketAddress add = new GatewayRemoteIpResolver().getRemoteIpAddrByRequest(request);
        if (add != null) {
            return add.getAddress().getHostAddress();
        }
        return "Unknown";
    }
}